<?php

/**
 * 首页
 * @copyright (c) 2013, Mr.Wang
 * @author Mr.Wang <281762391@qq.com>
 */
class CaiAction extends HomeAction {

    function _before_index() {
        $shop_id = format_int($_GET['shop_id']);
        if ($shop_id == 0) {
            $shop_id = format_int(cookie("shop_id"));
            if ($shop_id == 0) {
                $this->error("请先选择商家", U("Shop/Index"));
            } else {
                $this->redirect("Cai/Index/?shop_id={$shop_id}");
            }
        }
        $shop = M("Shop")->find($shop_id);
        $this->seo("{$shop['shop_name']} - 菜单列表");
    }

    function _filter(&$map) {
        $shop_id            = $_GET['shop_id'];
        $map['cai_shop_id'] = $shop_id;
        $this->assign("shop_id", $shop_id);
    }

    function view() {
        $name  = $this->getActionName();
        $model = M($name);
        $id    = $_REQUEST [$model->getPk()];
        if (!$id) {
            $id = $_REQUEST ['id'];
        }
        $vo = $model->find($id);
        $this->seo("{$vo['cai_name']}");
        $this->assign('vo', $vo);
        $this->display();
    }

}
